home *** CD-ROM | disk | FTP | other *** search
/ Complete Linux / Complete Linux.iso / docs / devel / tcl / tclx7_31.z / tclx7_31 / tcldev / tclX7.3a-p1 / tests / string.test < prev    next >
Encoding:
Text File  |  1994-01-23  |  5.5 KB  |  241 lines

  1. #
  2. # string.test
  3. #
  4. # Tests for the cindex, clength, crange, replicate, csubstr, and translit
  5. # commands.
  6. #---------------------------------------------------------------------------
  7. # Copyright 1992-1993 Karl Lehenbauer and Mark Diekhans.
  8. #
  9. # Permission to use, copy, modify, and distribute this software and its
  10. # documentation for any purpose and without fee is hereby granted, provided
  11. # that the above copyright notice appear in all copies.  Karl Lehenbauer and
  12. # Mark Diekhans make no representations about the suitability of this
  13. # software for any purpose.  It is provided "as is" without express or
  14. # implied warranty.
  15. #------------------------------------------------------------------------------
  16. # $Id: string.test,v 3.0 1993/11/19 06:58:05 markd Rel $
  17. #------------------------------------------------------------------------------
  18. #
  19.  
  20. if {[info procs test] != "test"} then {source testlib.tcl}
  21.  
  22. # Test the 'cindex' command.
  23.  
  24. Test string-1.1 {cindex tests} {
  25.     cindex ABCDEFG 1
  26. } 0 {B}
  27.  
  28. Test string-1.2 {cindex tests} {
  29.     cindex ABCDEFG 3+1
  30. } 0 {E}
  31.  
  32. Test string-1.3 {cindex tests} {
  33.     cindex ABCDEFG 3*2
  34. } 0 {G}
  35.  
  36. Test string-1.4 {cindex tests} {
  37.     cindex ABCDEFG 7
  38. } 0 {}
  39.  
  40. Test string-1.5 {cindex tests} {
  41.     cindex ABCDEFG end-2
  42. } 0 {E}
  43.  
  44. Test string-1.6 {cindex tests} {
  45.     cindex ABCDEFG len-3
  46. } 0 {E}
  47.  
  48. Test string-1.7 {cindex tests} {
  49.     cindex ABCDEFG lenx-3
  50. } 1 {syntax error in expression "7x-3"}
  51.  
  52. Test string-1.8 {cindex tests} {
  53.     cindex ABCDEFG
  54. } 1 {wrong # args: cindex string indexExpr}
  55.  
  56. Test string-1.9 {cindex tests} {
  57.     cindex ABCDEFG 1 10
  58. } 1 {wrong # args: cindex string indexExpr}
  59.  
  60. # Test the 'clength' command.
  61.  
  62. Test string-2.1 {clength tests} {
  63.     clength ABCDEFG
  64. } 0 {7}
  65.  
  66. Test string-2.2 {clength tests} {
  67.     clength "ABCD XYZ"
  68. } 0 {8}
  69.  
  70. Test string-2.3 {clength tests} {
  71.     clength
  72. } 1 {wrong # args: clength string}
  73.  
  74. # Test the crange command.
  75.  
  76. Test string-3.1 {crange tests} {
  77.     crange ABCDEFG 1 3
  78. } 0 {BCD}
  79.  
  80. Test string-3.2 {crange tests} {
  81.     crange ABCDEFG 2 end
  82. } 0 {CDEFG}
  83.  
  84. Test string-3.3 {crange tests} {
  85.     set foo [replicate ABCD 500]
  86.     crange $foo 25*4 500-1
  87. } 0 [replicate ABCD 100]
  88.  
  89. Test string-3.4 {crange tests} {
  90.     crange
  91. } 1 {wrong # args: crange string firstExpr lastExpr}
  92.  
  93. Test string-3.5 {crange tests} {
  94.     crange ABCD 4 1
  95. } 0 {}
  96.  
  97. Test string-3.6 {crange tests} {
  98.     crange ABCD end-2 len-1
  99. } 0 {BCD}
  100.  
  101. Test string-3.7 {crange tests} {
  102.     crange ABCD len-3 end-1
  103. } 0 {BC}
  104.  
  105. Test string-3.8 {crange tests} {
  106.     crange ABCD lenx-3 end-1
  107. } 1 {syntax error in expression "4x-3"}
  108.  
  109. # Test the 'replicate' command
  110.  
  111. Test string-4.1 {replicate tests} {
  112.     replicate AbCd 4
  113. } 0 {AbCdAbCdAbCdAbCd}
  114.  
  115. Test string-4.2 {replicate tests} {
  116.     replicate X 1000
  117. } 0 "[replicate X 250][replicate X 250][replicate X 250][replicate X 250]"
  118.  
  119. Test string-4.3 {replicate tests} {
  120.     replicate X
  121. } 1 {wrong # args: replicate string countExpr}
  122.  
  123. # Test the csubstr command.
  124.  
  125. Test string-5.1 {csubstr tests} {
  126.     csubstr ABCDEFG 1 2+1
  127. } 0 {BCD}
  128.  
  129. Test string-5.2 {csubstr tests} {
  130.     csubstr ABCDEFG 1+1 end
  131. } 0 {CDEFG}
  132.  
  133. Test string-5.3 {csubstr tests} {
  134.     set foo [replicate ABCD 500]
  135.     csubstr $foo 25*4 100*4
  136. } 0 [replicate ABCD 100]
  137.  
  138. Test string-5.4 {csubstr tests} {
  139.     csubstr
  140. } 1 {wrong # args: csubstr string firstExpr lengthExpr}
  141.  
  142. Test string-5.5 {csubstr tests} {
  143.     csubstr ABCD 4 1
  144. } 0 {}
  145.  
  146. Test string-5.6 {csubstr tests} {
  147.     csubstr ABCD 1 end-1
  148. } 0 {BC}
  149.  
  150. Test string-5.7 {csubstr tests} {
  151.     csubstr ABCD len-2 end
  152. } 0 {CD}
  153.  
  154. Test string-5.8 {csubstr tests} {
  155.     csubstr ABCD 0 len
  156. } 0 {ABCD}
  157.  
  158. # Test the translit command.
  159.  
  160. Test string-6.1 {translit tests} {
  161.     set str "Captain Midnight Secret Decoder Ring"
  162.     translit {A-MN-Za-mn-z} {N-ZA-Mn-za-m} $str
  163. } 0 {Pncgnva Zvqavtug Frperg Qrpbqre Evat}
  164.  
  165. Test string-6.2 {translit tests} {
  166.     set str "Captain Midnight Secret Decoder Ring"
  167.     set str2 [translit {A-MN-Za-mn-z} {N-ZA-Mn-za-m} $str]
  168.     translit {A-MN-Za-mn-z} {N-ZA-Mn-za-m} $str2
  169. } 0 {Captain Midnight Secret Decoder Ring}
  170.  
  171. Test string-6.3 {translit tests} {
  172.     translit
  173. } 1 {wrong # args: translit from to string}
  174.  
  175. # Test the ctoken command
  176.  
  177. Test string-7.1 {ctoken tests} {
  178.     ctoken
  179. } 1 {wrong # args: ctoken strvar separators}
  180.  
  181. Test string-7.2 {ctoken tests} {
  182.     ctoken a b c
  183. } 1 {wrong # args: ctoken strvar separators}
  184.  
  185. Test string-7.3 {ctoken tests} {
  186.     set orgstr "  \t  this\tis \n  a   test   "
  187.     set s1 [ctoken orgstr " \t\n"]
  188.     set s1v $orgstr
  189.     set s2 [ctoken orgstr " \t\n"]
  190.     set s2v $orgstr
  191.     set s3 [ctoken orgstr " \t\n"]
  192.     set s3v $orgstr
  193.     set s4 [ctoken orgstr " \t\n"]
  194.     set s4v $orgstr
  195.     set s5 [ctoken orgstr " \t\n"]
  196.     set s5v $orgstr
  197.     list $s1 $s1v $s2 $s2v $s3 $s3v $s4 $s4v $s5 $s5v
  198. } 0 [list "this"  "\tis \n  a   test   " \
  199.           "is"    " \n  a   test   " \
  200.           "a"     "   test   " \
  201.           "test"  "   " \
  202.           ""      ""]
  203.  
  204. Test string-8.1 {cexpand tests} {
  205.     cexpand
  206. } 1 {wrong # args: cexpand string}
  207.  
  208. Test string-8.2 {cexpand tests} {
  209.     cexpand x y
  210. } 1 {wrong # args: cexpand string}
  211.  
  212. Test string-8.3 {cexpand tests} {
  213.     cexpand {\n\n\t}
  214. } 0 "\n\n\t"
  215.  
  216. Test string-8.4 {cexpand tests} {
  217.     cexpand {xxxxxxx\nx\nxxx\ta}
  218. } 0 "xxxxxxx\nx\nxxx\ta"
  219.  
  220. Test string-8.5 {cexpand tests} {
  221.     cexpand "[replicate a 100]$\\n\\t$\\\[[replicate b 100]"
  222. } 0 "[replicate a 100]$\n\t$\[[replicate b 100]"
  223.  
  224. Test string-9.1 {cequal tests} {
  225.     cequal
  226. } 1 {wrong # args: cequal string1 string2}
  227.  
  228. Test string-9.2 {cequal tests} {
  229.     cequal a b c
  230. } 1 {wrong # args: cequal string1 string2}
  231.  
  232. Test string-9.3 {cequal tests} {
  233.     cequal ab c
  234. } 0 0
  235.  
  236. Test string-9.3 {cequal tests} {
  237.     cequal abcded abcded
  238. } 0 1
  239.  
  240.  
  241.